package com.mz.mattress.client.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mz.mattress.api.entity.Member;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MemberMapper extends BaseMapper<Member> {

    @Select("select * from mz_member where mobile=#{mobile} and deleted=0 limit 1")
    Member selectByMobile(@Param("mobile") String mobile);

    @Select("select id,create_time,mobile,sex,weight,birthday from mz_member where nickname='微信用户'")
    List<Member> list();

    @Select("select id,create_time,mobile,sex,weight,birthday,count from mz_member where count=0 and create_time<#{date} order by id desc limit ${count}")
    List<Member> list0(@Param("date") String date, @Param("count") Integer count);

    @Select("select id,create_time,mobile,sex,weight,birthday,count from mz_member where count>0 and create_time<#{date} order by id desc limit ${count}")
    List<Member> list1(@Param("date") String date, @Param("count") Integer count);

    @Select("select id from mz_member where nickname='微信用户' and weight=0")
    List<Long> listId();

    //假手机号
    @Select("select mobile from mz_member where ISNULL(open_id) and deleted=0")
    List<String> mobileList();

    @Update("update mz_member set total=total+1 where id=#{id}")
    void incrementTotal(@Param("id") Long id);

}
